import axios from '@/utils/request'

// 获取文章列表数据
/**
 *
 * @param {*} id
 * @param {*} timestamp
 * @returns
 */
export function getArticle(id, timestamp) {
  return axios({
    url: '/v1_0/articles',
    // get 方式, 数据写在params中
    params: {
      channel_id: id, // 频道id
      timestamp // 时间戳
    }
  })
}

// 不感兴趣文章功能
/**
 *
 * @param {*} target // 不喜欢文章的id
 * @returns
 */
export function dislikeArt(target) {
  return axios({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target
    }
  })
}

// 举报文章
/**
 *
 * @param {*} target  举报文章的id
 * @param {*} type    举报文章的类型
 * @returns
 */
export function reportArt(target, type) {
  return axios({
    method: 'post',
    url: '/v1_0/article/reports',
    data: {
      target,
      type
    }
  })
}

// 获取文章详情
/**
 *
 * @param {*} id  文章id
 * @returns
 */
export function getArticleInfo(id) {
  return axios({
    url: `/v1_0/articles/${id}`
  })
}

// 取消关注用户
/**
 *
 * @param {*} target
 * @returns
 */
export function unFollowUser(target) {
  return axios({
    method: 'delete',
    url: `/v1_0/user/followings/${target}`
  })
}

// 关注作者
/**
 *
 * @param {*} target
 * @returns
 */
export function addFollowUser(target) {
  return axios({
    method: 'post',
    url: '/v1_0/user/followings',
    data: {
      target
    }
  })
}

/**
 * 取消点赞
 * @param {*} id 文章编号
 */
export const deleteLike = id => {
  return axios({
    method: 'delete',
    url: '/v1_0/article/likings/' + id
  })
}

/**
 * 添加点赞
 * @param {*} id 文章编号
 */
export const addLike = id => {
  return axios({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

/**
 * 取消不喜欢
 * @param {*} id 文章编号
 */
export const deleteDisLike = id => {
  return axios({
    method: 'delete',
    url: '/v1_0/article/dislikes/' + id
  })
}

/**
 * 添加不喜欢
 * @param {*} id 文章编号
 */
export const addDisLike = id => {
  return axios({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}
